﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sunimage.Spjg.BLL;
using Sunimage.Spjg.BLL.Helper;
using Sunimage.Spjg.BLL.SysMgr;
using Sunimage.Spjg.Common;
using Sunimage.Spjg.Web.Helper;

namespace Sunimage.Spjg.Web.UserClient
{
    public partial class Share : System.Web.UI.Page
    {
        FileBl fileBl = new FileBl();
        UserBl userBl = new UserBl();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            rptNote.DataSource = fileBl.GetAllPulbicFile();
            rptNote.DataBind();
        }

        protected void pager_PageChanged(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        protected void rptNote_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Download")
            {
                if (GsjUserHelper.Permissions.Split(',').Contains(((int)PermissionEnum.FileDownload).ToString()))
                {
                    Guid id = Guid.Parse(e.CommandArgument.ToString());
                    DiskFile file = fileBl.GetById(id);
                    FileUpDownHelper.Download(file.Title, file.Path);
                }
                else
                {
                    AlertHelper.ShowError("您没有下载文件的权限！", this.Page);
                }

            }
        }

        protected void rptNote_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Literal ltr = e.Item.FindControl("ltrOwnerName") as Literal;
            if (ltr != null)
            {
                DiskFile file = e.Item.DataItem as DiskFile;
                Common.User user = userBl.GetById(file.OwnerId);
                if (user != null)
                    ltr.Text = user.NickName;
                else
                    ltr.Text = AppConstant.DeleteUserNickname;
            }
        }
    }
}